package com.test.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.test.dao.OrderMapper;
import com.test.model.Order;


@RestController
public class OrderController {
	@Autowired
	OrderMapper orderMapper;
	
	//得到订单列表
	@RequestMapping("getOrder")
	public Map GetOrder(){
		Map m=new HashMap();
		List ls=new ArrayList();
		
		ls=orderMapper.selectAll();
		System.out.println();
		m.put("rs", ls);
		
		
		return m;
	}
	
	//修改订单
	@RequestMapping("submitOrder")
	public Map SubmitOrder(@RequestBody Order o){
		Map m=new HashMap();
		if(orderMapper.updateByPrimaryKeySelective(o)>0){
			
			m.put("rs", "Y");
		}else{
			m.put("rs", "N");
		}
		
		
		return m;
	}
	
	
	//添加订单
	@RequestMapping("addOrder")
	public Map AddOrder(@RequestBody Order o){
		Map m=new HashMap();
		if(orderMapper.insertSelective(o)>0){
			m.put("rs", "Y");
		}else{
			m.put("rs", "N");
		}
		
		
		return m;
	}
	
	//删除订单
	@RequestMapping("deleted")
	public Map Deleted(@RequestBody Order o){
		Map m=new HashMap();
		if(orderMapper.deleteByPrimaryKey(o.getId())>0){
			m.put("rs", "Y");
		}else{
			m.put("rs", "N");
		}
		
		return m;
	}
	

}
